

/**
* A number of somewhat helpful functions which act on the display.
*
**/


/**
 * A way to fire an event on object (such as a button or link) that has an
 * event.
 * Browser neutral (will use dispatchEvent if needed, otherwise uses fireEvent method)
 */
function fireCommand(commandToFire) {
    if (document.createEvent)
    {
        var evObj = document.createEvent('MouseEvents');
        evObj.initEvent('click', true, false);
        commandToFire.dispatchEvent(evObj);
    }
    else if (document.createEventObject)
    {
        commandToFire.fireEvent('onclick');
    }
}

/**
 * Fire an event on an object with the given ID.
 * convenience method for fireCommand.
 */
function fireCommandById(commandObjId)
{
    fireCommand(document.getElementById(commandObjId));
}


function toggleDisplay(field) {
    d = document.getElementById(field);
    if (d != null) {
        if (d.style.display == "none") {
            d.style.display = "";
        }
        else {
            d.style.display = "none";
        }
    }
}

function toggleVisible(fieldAry) {
    for (i = 0; i < fieldAry.length; i++) {
        d = document.getElementById(fieldAry[i]);
        if (d != null) {
            if (d.style.display) {
                d.style.display = (d.style.display == "none" ? "inherit" : "none");
            }
        }
    }
}

function setAryVisible(fieldAry, value) {
    for (i = 0; i < fieldAry.length; i++) {
        d = document.getElementById(fieldAry[i]);
        if (d != null) {
            if (d.style.display) {
                d.style.display = value;
            }
        }
    }
}

function switchActiveOnConditions(fieldAry_one, fieldAry_two, el, onConditions) {
    for (i = 0; i < onConditions.length; i++) {
        if (el.value == onConditions[i]) {
            setAryVisible(fieldAry_one, "table-row");
            setAryVisible(fieldAry_two, "none");
            return;
        }
    }
    setAryVisible(fieldAry_two, "table-row");
    setAryVisible(fieldAry_one, "none");
}

function switchActive(field_one, field_two, btn, titleField, activeOneText, activeTwoText, activeDisplayStyle) {
    //r = document.getElementById("advert_bottom");
    //r.innerHTML += "switchActive: field displays:";

    f1 = document.getElementById(field_one);
    f2 = document.getElementById(field_two);
    //r.innerHTML += 	"<br>f1: " + f1.style.display;
    //r.innerHTML += 	"<br>f2: " + f2.style.display;
    title = document.getElementById(titleField);
    if (f2.style.display == "none") {
        // switch the second to active:
        f1.style.display = "none";
        f2.style.display = activeDisplayStyle;
        btn.value = activeOneText;
        if (title != null) {
            title.innerHTML = activeTwoText;
        }
    }
    else {
        f2.style.display = "none";
        f1.style.display = activeDisplayStyle;
        btn.value = activeTwoText;
        if (title != null) {
            title.innerHTML = activeOneText;
        }
    }

}